/**
* @Title: caseHandle_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
* Company:中国平安
* ex-xieqi001
* @Project HIMS-FWA
* @date 2014年11月11日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('ApprovalPostCtrl', ['$scope','$state','CommunityService','FwaTabsetService','Modal','ApprovalPostService',
	                                function($scope,$state,CommunityService,FwaTabsetService,Modal,ApprovalPostService){
		
		$scope.barOption = {
				title:{
					text: '事件案件汇总',
			        x: 'left'
				},
				grid:{
					x:30,
					y:40,
					x2:10,
					y2:40,
					borderColor:'#fff'
				},
				xAxis : [{
		             type : 'category',
		             boundaryGap: true,
		             data : ['']
		         }],
		         series:[],
		         color:['#56C8E3','#F4AF74']
		};
		
		
		$scope.barLeftOption ={
				title:{
					text: '机构排名',
			        x: 'left'
				},
				grid:{
					x:30,
					y:40,
					x2:10,
					y2:40,
					borderColor:'#fff'
				},
				xAxis : [{
		             type : 'category',
		             boundaryGap: true,
		             data : ['']
		         }],
		         series:[],
		         color:['#56C8E3']
		};
		
		
		//获取echarts 数据
		ApprovalPostService.getQuestionProvider().success(function(res){
			$scope.barLeftOption.xAxis = [{
								             type : 'category',
								             boundaryGap: true,
								             data : res.providerNameList
								         }];
			
			$scope.barLeftOption.series = [{
											name:'案件数',
											barWidth:15,
											type:'bar',
											data:res.numList
										}];
		});
		//获取echarts 数据
		ApprovalPostService.getQuestionCount().success(function(res){
			$scope.barOption.xAxis = [{
	             type : 'category',
	             boundaryGap: true,
	             data : res.dateList
	         }];
			
			var barSeries  = [];
			barSeries.push({
				name:'事件调查',
				type:'bar',
				data:res.investigatedData
			},{
				name:'稽核案件',
				type:'bar',
				data:res.auditData
			});
			$scope.barOption.series = barSeries; 
		});
		
		$scope.columns = [
			          		{
			          			label : '案件号',
			          			map : 'caseCode',
			          			width : '10%',
			          			 cellTemplate:'<a  ng:bind="data.caseCode" ng-click="queryAuditCase(data)"></a>'},
			          		{
			          			label : '机构名称',
			          			map : 'orgName',
			          			width : '15%'
			          		}, {
			          			label : '受理时间',
			          			map : 'auditDate',
			          			width : '17%'
			          		}, {
			          			label : '不合理费用',
			          			map : 'totalDeduction',
			          			width : '10%'
			          		}, {
			          			label : '告知时间',
			          			map : 'notifyDate',
			          			width : '15%'
			          		}, {
			          			label : '机构确认时间',
			          			map : 'affirmDate',
			          			width : '15%'
			          		}, {
			          			label : '案件状态',
			          			map : 'statusName',
			          			width : '10%'
			          		}, {
			          			label : '操作',
			          			map : 'operation',
			          			width : '8%',
			          			cellClass:'text-center',
			          			cellTemplate:'<a  ng-click="operation(data);">审批</a>'
			          		}
			          	];
		var code = '6';
		
		//查询
		function query() {
			ApprovalPostService.queryCaseTaskList(code).success(function(res){
				if (res) {
	        		$scope.tableData = res.result;
	        		$scope.totalCount = res.total;
	    		}
			});
		}
		
		//查看
		$scope.queryAuditCase = function(data) {
			FwaTabsetService.selectTab("caseDetailView.detail",{caseCode:data.caseCode,problemCode:data.relatedCode});
        }
		
		//审批
		$scope.operation = function(data){
			FwaTabsetService.selectTab('conclusionApprovement.caseAuditApprovement',{caseCode:data.caseCode,problemCode:data.relatedCode,urlFlag:code});
		}
		var isFlag = true;
		//跳转路由监听
		$scope.$on('$stateChangeSuccess', function(event , toState, toParams, fromState){
			if(toState.name && toState.name.indexOf('workingArea.approvalPost') != -1) {
				if (isFlag) {
					query();
					isFlag = false;
				}
				else {
					isFlag = true;
				}
			}
		});
		
		if (isFlag) {
			query();
			isFlag = false;
		}
		else {
			isFlag = true;
		}
		
	}]);
})();
